<template>
  <view :style="colorStyle">
    <view
      class="infobox1 flex aitems"
      :style="{ height: `${menuInfo.top + menuInfo.height}px` }"
    >
      <view class="block2 flex aitems" @click="back">
        <image src="@/static/img14.png" class="back" mode=""></image>
      </view>
      <view
        class="block1 flex aitems"
        @click="gourl(`/pages/seller/search?id=${user.id}`)"
      >
        <view class="icon">
          <u-icon name="search" size="20" color="#fff"></u-icon>
        </view>
        <view class="input cfff f28"> 搜索 </view>
      </view>
    </view>
    <view class="bg">
      <image :src="user.backImg" mode="aspectFill"></image>
    </view>

    <!-- <view :style="navTitleModuleStyle2"> </view> -->

    <view class="infobox2 flex aitems" :style="navTitleModuleStyle2">
      <image :src="user.logo" mode="aspectFill"></image>
      <view class="block1">
        <view class="info1 cfff f36 fontWeight">
          {{ user.name }}
        </view>
        <view class="info2 flex aitems">
          <image
            src="@/static/img7.png"
            mode=""
            v-for="(item, index, key) in user.score"
            :key="'score' + index"
          ></image>
          <image
            src="@/static/img47.png"
            mode=""
            v-for="(item, index, key) in 5 - user.score"
            :key="'score' + index"
          ></image>
        </view>
      </view>
    </view>

    <view class="infobox3">
      <view class="block2 flex aitems sa f32 cfff">
        <view class="info1" @click="morenChange">
          <view :class="screenType == 1 ? 'tip1 themeColor' : 'tip1'">
            默认
          </view>
        </view>
        <view class="info1 flex aitems" @click="priceChange">
          <view :class="priceType !== '' ? 'tip1 themeColor' : 'tip1'">
            价格
          </view>
          <view class="arrow-down-fill">
            <u-icon
              name="arrow-up-fill"
              :color="priceType == 2 ? 'var(--view-theme)' : '#fff'"
              size="8"
            ></u-icon>
            <u-icon
              name="arrow-down-fill"
              :color="priceType == 1 ? 'var(--view-theme)' : '#fff'"
              size="8"
            ></u-icon>
          </view>
        </view>
        <view class="info1 flex aitems" @click="saleChange">
          <view :class="saleType !== '' ? 'tip1 themeColor' : 'tip1'">
            销量
          </view>
          <view class="arrow-down-fill">
            <u-icon
              name="arrow-up-fill"
              :color="saleType == 2 ? 'var(--view-theme)' : '#fff'"
              size="8"
            ></u-icon>
            <u-icon
              name="arrow-down-fill"
              :color="saleType == 1 ? 'var(--view-theme)' : '#fff'"
              size="8"
            ></u-icon>
          </view>
        </view>
        <view class="info1 flex aitems" @click="viewTabChange">
          <image
            src="@/static/img91.png"
            v-if="viewType == 1"
            class="icon"
            mode=""
          ></image>
          <image
            src="@/static/img89.png"
            v-if="viewType == 2"
            class="icon"
            mode=""
          ></image>
        </view>
      </view>
    </view>

    <view class="" style="height: 436rpx"> </view>
    <block v-if="!loadingPage">
      <x-skeleton
        type="list"
        :loading="true"
        v-for="(item, indexs) in 10"
        :key="'skeleton' + indexs"
      >
        <view>列表</view>
      </x-skeleton>
    </block>
    <view class="goodsModule" v-if="loadingPage && viewType == 1">
      <view
        class="goodslist flex"
        v-for="(item, index) in list"
        :key="item.id"
        @click.stop="gourl(`/pages/goods/detail?id=${item.id}`)"
      >
        <image :src="item.img" class="goodsimg" mode="aspectFill"></image>
        <view class="goodsinfo flex between column">
          <view class="block1">
            <text class="goodsname ellipsis2 c1F1F1F f28">
              {{ item.name }}
            </text>
            <view class="goodslabel flex aitems wrap">
              <view
                class="label f22 fontWeight"
                v-for="(items, indexs) in item.tagName
                  ? item.tagName.split(',')
                  : 0"
                :key="'tagName' + indexs"
              >
                {{ items }}
              </view>
            </view>
            <view class="goodssale c858585 f22">
              销量:{{
                Number(item.salesVolume + item.salesVolumeVirtual).toFixed(0)
              }}
            </view>
          </view>
          <view class="block2 flex fontWeight">
            <view class="info1 flex">
              <view class="unit f24"> ￥ </view>
              <view class="price f40">
                {{ item.goodsPrice }}
              </view></view
            ><view class="info2 flex aitems">
              <view class="unit f20"> ￥ </view>
              <view class="price f28">
                {{ item.marketPrice }}
              </view></view
            >
          </view>
        </view>
      </view>
    </view>

    <view
      class="goodsModule flex wrap between"
      v-if="loadingPage && viewType == 2"
    >
      <view
        class="goodslist2"
        v-for="(item, index) in list"
        :key="item.id"
        @click.stop="gourl(`/pages/goods/detail?id=${item.id}`)"
      >
        <image :src="item.img" class="goodsimg" mode="aspectFill"></image>
        <view class="goodsinfo flex between column">
          <view class="block1">
            <text class="goodsname ellipsis2 c1F1F1F f28">
              {{ item.name }}
            </text>
            <view class="goodslabel flex aitems wrap">
              <view
                class="label f22 fontWeight"
                v-for="(items, indexs) in item.tagName
                  ? item.tagName.split(',')
                  : 0"
                :key="'label' + indexs"
              >
                {{ items }}
              </view>
            </view>
          </view>
          <view class="block2 flex flex aitems between">
            <view class="flex fontWeight">
              <view class="info1 flex aitems">
                <view class="unit f24"> ￥ </view>
                <view class="price f32">
                  {{ item.goodsPrice }}
                </view>
              </view>
              <view class="info2 flex aitems">
                <view class="unit f20"> ￥ </view>
                <view class="price f28">
                  {{ item.marketPrice }}
                </view>
              </view>
            </view>
            <view class="goodssale c858585 f22">
              销量:{{
                Number(item.salesVolume + item.salesVolumeVirtual).toFixed(0)
              }}
            </view>
          </view>
        </view>
      </view>
    </view>

    <nodata v-if="list.length == 0" />
    <view class="" style="height: 100rpx"> </view>

    <custom-tab-bar
      :activeIndex="0"
      :sellerId="user.id"
      :user="user"
      :list="[]"
    ></custom-tab-bar>
  </view>
</template>

<script>
import customTabBar from "./tabbar.vue";
import { getToken, setStorage, getStorage } from "@/utils/storage.js";
import { sellerInfo, goodsPage } from "@/servers/servers.js";
import { HTTP_STATUS } from "@/servers/config.js";
import colors from "@/mixins/color";
import { loading, go, back } from "@/utils/wxAPI";
export default {
  mixins: [colors],
  components: {
    customTabBar,
  },
  data() {
    return {
      menuInfo: {},
      navTitleModuleStyle: "",
      navTitleModuleStyle2: "",
      user: {
        score: 0,
      },
      options: {},

      screenType: "",
      priceType: "",
      saleType: "",
      params: {},
      loadingPage: false,
      total: 0,
      list: [],
      current: 1,
      viewType: 1, //1列表 2左右
    };
  },
  async onLoad(options) {
    this.options = options;
    // #ifdef MP-WEIXIN
    this.menuInfo = getApp().globalData.menuInfo;
    this.navTitleModuleStyle = `top:${
      this.menuInfo.height + this.menuInfo.top + 10
    }px`;
    this.navTitleModuleStyle2 = `top:calc(${
      this.menuInfo.height + this.menuInfo.top
    }px)`;
    // #endif
    // #ifdef H5
    this.navTitleModuleStyle2 = `top:calc(100rpx)`;
    // #endif

    if (getToken()) {
      this.sellerInfo();
      this.handleGoodsPage();
    }
  },
  methods: {
    async sellerInfo() {
      loading();
      let { data } = await sellerInfo({
        id: this.options.id,
      });
      if (data.code == HTTP_STATUS.RUSELT_SUCCESS) {
        let info = data.data;
        this.user = info;
      }
      uni.hideLoading();
    },
    saleChange() {
      this.priceType = "";
      this.screenType = "";
      if (this.saleType == "") {
        this.saleType = 2;
      } else if (this.saleType == 2) {
        this.saleType = 1;
      } else if (this.saleType == 1) {
        this.saleType = "";
      }
      this.params.orderByAsc = this.saleType == 1 ? "salesVolume" : "";
      this.params.orderByDesc = this.saleType == 2 ? "salesVolume" : "";
      this.current = 1;
      this.handleGoodsPage();
    },
    priceChange() {
      this.saleType = "";
      this.screenType = "";
      if (this.priceType == "") {
        this.priceType = 2;
      } else if (this.priceType == 2) {
        this.priceType = 1;
      } else if (this.priceType == 1) {
        this.priceType = "";
      }
      this.params.orderByAsc = this.priceType == 1 ? "goodsPrice" : "";
      this.params.orderByDesc = this.priceType == 2 ? "goodsPrice" : "";
      this.current = 1;
      this.handleGoodsPage();
    },
    viewTabChange() {
      if (this.viewType == 1) {
        this.viewType = 2;
      } else {
        this.viewType = 1;
      }
    },
    morenChange() {
      this.priceType = "";
      this.saleType = "";
      this.screenType = 1;
      this.current = 1;
      this.params = {};
      this.handleGoodsPage();
    },
    async handleGoodsPage() {
      loading();
      let { data } = await goodsPage({
        current: this.current,
        size: 10,
        ...this.params,
        sellerId: this.options.id,
      });
      if (data.code == HTTP_STATUS.RUSELT_SUCCESS) {
        let list = data.data.records;
        this.total = data.data.total;
        if (this.current == 1) {
          this.list = list;
        } else {
          this.list.push(...list);
        }
        setTimeout(() => {
          this.loadingPage = true;
        }, 500);
      }
      uni.stopPullDownRefresh();
      uni.hideLoading();
    },
    back() {
      back();
    },
    gourl(url) {
      go(url);
    },
  },
  onReachBottom() {
    if (this.list.length == this.total) return;
    this.current += 1;
    this.handleGoodsPage();
  },
  onPullDownRefresh() {
    this.sellerInfo();
    this.current = 1;
    this.handleGoodsPage();
  },
};
</script>
<style>
/* #ifdef MP-WEIXIN */
page {
  background: #f5f5f5;
}

/* #endif */
</style>
<style lang="scss" scoped>
page {
  background: #f5f5f5;
}

.bg {
  position: fixed;
  top: 0;
  width: 100%;
  height: 436rpx;
  z-index: 999;

  image {
    width: 100%;
    height: 100%;
  }
}

.infobox1 {
  // background: #fff;
  padding: 0 0 22rpx 0;
  position: fixed;
  width: 100%;
  z-index: 99999;
  /* #ifdef H5 */
  height: 90rpx;
  /* #endif */

  .block2 {
    position: absolute;
    bottom: 26rpx;
    left: 30rpx;
    z-index: 999;

    .back {
      width: 48rpx;
      height: 48rpx;
    }

    .headimg {
      width: 64rpx;
      height: 64rpx;
      border-radius: 57rpx;
      margin-left: 10rpx;
    }
  }

  .block1 {
    border-radius: 44rpx;
    background: rgba(255, 255, 255, 0.4);
    width: 430rpx;
    /* #ifdef H5 */
    width: calc(100% - 30rpx - 30rpx - 48rpx - 40rpx);
    /* #endif */
    position: absolute;
    bottom: 18rpx;
    padding: 0 4rpx;
    left: calc(20rpx + 48rpx + 40rpx);
    height: 64rpx;

    .icon {
      margin-left: 28rpx;
    }

    .input {
      margin-left: 16rpx;
    }

    .btn {
      position: absolute;
      right: 0;
      border-radius: 44rpx;
      background: var(--view-theme);
      padding: 15rpx 47rpx;
    }
  }
}

.infobox2 {
  position: fixed;
  margin: 0 30rpx 0;
  z-index: 999;
  padding: 54rpx 0 0;
  width: calc(100% - 30rpx - 54rpx);

  image {
    width: 88rpx;
    height: 88rpx;
    border-radius: 16rpx;
  }

  .block1 {
    margin-left: 16rpx;
    width: calc(100% - 16rpx - 88rpx);

    .info1 {
    }

    .info2 {
      margin: 8rpx 0 0;

      image {
        width: 30rpx;
        height: 30rpx;
        margin: 0 12rpx 0 0;
      }
    }
  }
}

.infobox3 {
  position: fixed;
  top: 0;
  width: 100%;
  height: 436rpx;
  z-index: 999;

  .block2 {
    // margin: 40rpx 0 0;
    position: absolute;
    bottom: 24rpx;
    width: 100%;

    .info1 {
      .icon {
        width: 30rpx;
        height: 30rpx;
      }

      .tip1 {
      }

      .arrow-down-fill {
        margin-left: 12rpx;
      }
    }
  }
}

.goodsModule {
  margin: 30rpx 30rpx 0;

  .goodslist {
    background: #fff;
    border-radius: 24rpx;
    padding: 16rpx;
    margin: 0 0 24rpx 0;

    .goodsimg {
      width: 230rpx;
      height: 230rpx;
      border-radius: 24rpx;
    }

    .goodsinfo {
      width: calc(100% - 230rpx - 16rpx);
      margin-left: 16rpx;
      height: 260rpx;

      .block1 {
        width: 100%;

        .goodsname {
        }

        .goodslabel {
          margin: 16rpx 0;

          .label {
            color: var(--view-theme);
            padding: 4rpx 18rpx;
            border: 1px solid var(--view-theme);
            border-radius: 8rpx;
            margin: 0 20rpx 0 0;
          }
        }
      }

      .block2 {
        color: var(--view-theme);

        .info1 {
          .unit {
            position: relative;
            top: 16rpx;
          }

          .price {
          }
        }
        .info2 {
          text-decoration: line-through;
          margin-left: 10rpx;
          color: #999;
        }
      }
    }
  }

  .goodslist2 {
    background: #fff;
    border-radius: 24rpx;
    padding: 16rpx 0;
    width: 335rpx;
    margin: 0 0 24rpx 0;

    .goodsimg {
      width: 303rpx;
      height: 303rpx;
      border-radius: 24rpx;
      margin: auto;
    }

    .goodsinfo {
      width: 303rpx;
      margin: auto;
      padding: 16rpx 0 0;
      // width: calc(100% - 230rpx - 16rpx);
      // margin-left: 16rpx;
      // height: 260rpx;

      .block1 {
        width: 100%;

        .goodsname {
        }

        .goodslabel {
          margin: 16rpx 0;

          .label {
            color: var(--view-theme);
            padding: 4rpx 18rpx;
            border: 1px solid var(--view-theme);
            border-radius: 8rpx;
            margin: 0 20rpx 0 0;
          }
        }
      }

      .block2 {
        color: var(--view-theme);

        .info2 {
          text-decoration: line-through;
          margin-left: 8rpx;
          color: #999;
        }

        .info1 {
          .unit {
            position: relative;
            // top: 16rpx;
          }

          .price {
          }
        }
      }
    }
  }
}
</style>
